package com.yuandian.customer.perception.controller;

import com.yuandian.api.customer_perception.po.BusinessStatisticsParams;
import com.yuandian.api.customer_perception.po.DayReportParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.customer.perception.service.IBusinessStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 说明：业务统计controller
 * @Author yanjun
 * @Date 2021/3/17 15:24
 */
@RestController
@RequestMapping("/business/statistics")
public class BusinessStatisticsController {

    @Autowired
    private IBusinessStatisticsService businessStatisticsService;

    /**
     * 查询业务统计列表
     * @param params 业务统计请求参数对象
     * @return 通用返回对象
     */
    @PostMapping("/list")
    public R list(@RequestBody BusinessStatisticsParams params) {
        return businessStatisticsService.queryBusinessStatisticsList(params);
    }
    /**
     * 根据系统id获取已确认的业务列表
     * @param systemId 系统id
     * @param regionalCode 地市id
     * @return 通用返回对象
     */
    @GetMapping("/queryBusinessStatisticsListNoPage/{systemId}/{regionalCode}/{businessHall}")
    public R queryBusinessStatisticsListNoPage(@NotNull @PathVariable String systemId,@PathVariable String regionalCode,@PathVariable String businessHall) {
        BusinessStatisticsParams params=new BusinessStatisticsParams();
        if (systemId!=null&&!"".equals(systemId)&&!"null".equals(systemId)&&!"undefined".equals(systemId) ){
            params.setSystemId(Integer.valueOf(systemId));
        }
        if (regionalCode!=null&&!"".equals(regionalCode)&&!"null".equals(regionalCode)&&!"undefined".equals(regionalCode)){
            params.setRegionalCode(regionalCode);
        }
        if (businessHall!=null&&!"".equals(businessHall)&&!"null".equals(businessHall)&&!"undefined".equals(businessHall)){
            params.setBusinessHall(businessHall);
        }
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        Date startDate=calendar.getTime();
        params.setStartTime(simpleDateFormat.format(startDate));
        calendar.set(Calendar.HOUR_OF_DAY,23);
        calendar.set(Calendar.MINUTE,59);
        calendar.set(Calendar.SECOND,0);
        Date endDate=calendar.getTime();
        params.setEndTime(simpleDateFormat.format(endDate));
        return businessStatisticsService.queryBusinessStatisticsListNoPage(params);
    }

    /**
     * 查询运维日报业务统计(地市)topN
     * @param params 运维日报请求参数
     * @return 通用返回对象
     */
    @PostMapping("/queryReportBusinessAreaTopN")
    public R queryReportBusinessAreaTopN(@RequestBody DayReportParams params) {
        return businessStatisticsService.queryReportBusinessAreaTopN(params);
    }

    /**
     * 查询运维日报业务统计(营业厅)topN
     * @param params 运维日报请求参数
     * @return 通用返回对象
     */
    @PostMapping("/queryReportBusinessHallTopN")
    public R queryReportBusinessHallTopN(@RequestBody DayReportParams params) {
        return businessStatisticsService.queryReportBusinessHallTopN(params);
    }

    /**
     * 查询运维日报业务失败统计topN
     * @param params 运维日报请求参数
     * @return 通用返回对象
     */
    @PostMapping("/queryReportBusinessFailTopN")
    public R queryReportBusinessFailTopN(@RequestBody DayReportParams params) {
        return businessStatisticsService.queryReportBusinessFailTopN(params);
    }
}
